<?php
include 'chat/config.inc.php';
//获取平台的get
$username = @$_POST['username'];
$userimg = mysql_query("select img from wwk_chat_user where username = '{$username}'");
$userimgInfo = mysql_fetch_row($userimg);
if ($userimgInfo[0]) {
  $a = array('code' => 0, 'msg' => '不允许多次上传头像');
  echo json_encode($a);exit;
}
$file = $_FILES['avatar'];
$path = 'chatstatic/images/avatar/';
$imgname = time() . mt_rand(1000, 9999) . '.jpg';
$result = move_uploaded_file($file['tmp_name'],$path . $imgname);
$img = 'http://' . $_SERVER['HTTP_HOST'] . '/chatstatic/images/avatar/' . $imgname;
$add_sql = "update wwk_chat_user set img = '{$img}' where username = '{$username}'";
  $result = mysql_query($add_sql);

$a = array('code' => 1, 'img' => $img);
echo json_encode($a);

?>